package com.example.bpmn.monitor;

import io.micrometer.core.instrument.MeterRegistry;
import org.camunda.bpm.engine.RuntimeService;
import org.springframework.stereotype.Component;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.PostConstruct;

@Component
@RequiredArgsConstructor
public class ProcessMetrics {
    
    private final RuntimeService runtimeService;
    private final MeterRegistry registry;
    
    @PostConstruct
    public void init() {
        // 注册活动流程实例数量指标
        registry.gauge("process.active.instances", 
            this,
            (pm) -> pm.getActiveProcessCount());
    }
    
    private int getActiveProcessCount() {
        return runtimeService.createProcessInstanceQuery()
            .active()
            .list()
            .size();
    }
} 